#include<iostream>
using namespace std;
class Goods{
public:
	Goods(){
		weight=0;
		next=NULL;
		cout<<"创建了一个重量为"<<weight<<"的货物"<<endl;
	}
	Goods(int w){
		weight=w;
		next=NULL;
		total_w+=weight;
	}
	~Goods(){
		total_w-=weight;
		cout<<"删除了一箱重量"<<weight<<"货物"<<endl;
	}
	static int getTotelWeight(){
		return total_w;
	}
	Goods *next;
private:
	int weight;//货物重量
	static int total_w;//仓库总重量

};

int Goods::total_w=0;

void buy(Goods *&p_head,int w){
	Goods *newGoods=new Goods(w);
	if(p_head==NULL){
		p_head=newGoods;
	}else{
		newGoods->next=p_head;
		p_head=newGoods;
	}
}

void sale(Goods *& head){
	if(head==NULL){
		cout<<"仓库中没有货了"<<endl;
	}
	Goods *temp=head;
	head=head->next;
	delete head;
	cout<<"买出一件货物!"<<endl;

}

int main9(){
	int choice=0,w;
	Goods *header=NULL;
	do{
		cout<<"0 退出（exit）"<<endl;
		cout<<"1 进货"<<endl;
		cout<<"2 出货"<<endl;
		cin>>choice;
		switch(choice){
		case 1:
			cout<<"请输入要进货的重量"<<endl;
			cin>>w;
			buy(header,w);
			break;
		case 2:
			sale(header);
			break;
		case 0:
			return 0;
			break;
		default:
			cout<<"----请输入0、1、2数值----"<<endl;
			continue;
		}
		cout<<"当前仓库的总重量是："<<Goods::getTotelWeight()<<endl;
	}while(1);

	return 0;
}
